package com.zhi.service.impl;

import com.zhi.dao.GradeTeacherRepository;
import com.zhi.entity.GradeTeacher;
import com.zhi.service.GradeTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;

@Service
public class GradeTeacherServiceImpl implements GradeTeacherService {
	
	@Autowired
	private GradeTeacherRepository gradeTeacherRepository;

	@Override
	public List<GradeTeacher> getEntityList() {
		return gradeTeacherRepository.findAll();
	}
	
	@Override
	public List<Object[]> getEntityListWithCodeName() {
		return gradeTeacherRepository.getEntityListWithCodeName();
	}
	

	@Override
	public Page<GradeTeacher> getEntityListWithCodeName(Pageable pageable) {
		return gradeTeacherRepository.getEntityListWithCodeName(pageable);
	}

	@Override
	public GradeTeacher getOne(Integer id) {
		return gradeTeacherRepository.getOne(id);
	}
	
	@Override
	public GradeTeacher findOne(GradeTeacher gradeTeacher) {
		Example<GradeTeacher> example =Example.of(gradeTeacher);
		Optional<GradeTeacher> optional = gradeTeacherRepository.findOne(example);
		if(optional == null) {
			return null;
		}else {
			return optional.get();
		}
	}

	@Override
	public List<GradeTeacher> findAll(GradeTeacher gradeTeacher){
		Example<GradeTeacher> example =Example.of(gradeTeacher);
		List<GradeTeacher> list = gradeTeacherRepository.findAll(example);
		return list;
	}

	@Override
	public void save(GradeTeacher GradeTeacher) {
		gradeTeacherRepository.save(GradeTeacher);
	}

	@Override
	public void saveAll(List<GradeTeacher> gradeTeachers){
		gradeTeacherRepository.saveAll(gradeTeachers);
	}

	@Override
	public void edit(GradeTeacher GradeTeacher) {
		gradeTeacherRepository.save(GradeTeacher);
	}

	@Override
	public void delete(Integer id) {
		gradeTeacherRepository.deleteById(id);
	}

	@Override
	public void deleteByGradeId(String gradeId){
		gradeTeacherRepository.deleteByGradeId(gradeId);
	}

	@Override
	public Integer count(GradeTeacher GradeTeacher) {
		Example<GradeTeacher> example =Example.of(GradeTeacher);
		return (int) gradeTeacherRepository.count(example);
	}


}
